<template>
  <FListV2 size="small" v-loading="loading"
           :selectedKey="selectedKey"
           @doubleClick="doubleClick"
           @select="selectChange"
           title-name="realname"
           :data-source="lastUsers">
  </FListV2>
</template>

<script>
import {getAction} from '@/request/BaseRequest';
import {UserConfig} from '@/components/UserSelectorModal/DefaultUserConfig';
import {guid} from '@/utils/CommonUtils';
import FListV2 from '@/components/FListV2/index.vue';

export default {
  name: "LastUserList",
  components: {FListV2},
  data() {
    return {
      selectedKey: undefined,
      loading: false,
      lastUsers: []
    };
  },
  mounted() {
    this.loadLastUsers();
  },
  methods: {
    selectChange(user) {
      this.selectedKey = user.id;
    },
    doubleClick(user) {
      let res = this.createUserSelection(user);
      this.$emit('create', res);
    },
    createUserSelection(user) {
      let res = JSON.parse(JSON.stringify(UserConfig));
      res.type = 'user';
      res.userId = user.id;
      res.userName = user.realname;
      res.configName = user.realname;
      res.id = guid();
      return res;
    },
    loadLastUsers() {
      this.loading = true;
      getAction('/base/loadLastUsers').then(data => {
        if (data.success) {
          if (!data.result) data.result = [];
          this.lastUsers = data.result;
        } else {
          this.$notification.error({message: data.message, result: data.result, duration: 3});
        }
        this.loading = false;
      });
    },
  }
};
</script>

<style scoped>

</style>
